import Vuex from 'vuex'
let store=()=>new Vuex.Store({
  state:{
     /**common */
     Token:'' ,//  登录token凭证
     userInfo:sessionStorage.getItem('userInfo')||{} ,//用户基本信息
     isCollapse:false , //左侧导航是否收缩
     btnListTree:sessionStorage.getItem('btnListTree')||{} , //按钮权限
     menuTree:sessionStorage.getItem('menuTree')||[],//路由拦截，左侧菜单
     /**table */
     updateTable:false,//是否刷新列表
     page:1,//当前页
     pageSize:15,//每页显示条数
     searchParam:{},//表单查询参数
     echartDialog:false,//列表展示图表
     sortBy:'DESC',//排序规则
     sortField:'',//排序字段
     selectRows:[],//列表选中的行
     outImport:true,//是否可以导出
     /**表单 */
     treeStyle:{'treeNum1':false},//树形有多少个就设置多少个
     inputBlur:false,//监听失去焦点事件
     inputName:'',//监听当前文本框
     inputFocus:false,//监听获取焦点事件
     inputChange:false,//监听改变的值
     editData:{},//编辑数据
     dialogVisible:false,//弹窗
     dialogType:'',//弹窗类型
  },
  mutations:{
    setToken(state,data:string){
      state.Token=data
    },
    setUserInfo(state,data){
      state.userInfo=data
    },
    setCollapse(state,data:boolean){
      state.isCollapse=data
    },
    setBtnListTree(state,data){
      state.btnListTree=data
    },
    setMenuTree(state,data){
      state.menuTree=data
    },
    //
    setUpdateTable(state){
      state.updateTable=!state.updateTable
    },
    setPage(state,data:number){
      state.page=data
    },
    setPageSize(state,data:number){
      state.pageSize=data
    },
    setSearchParam(state,data){
      state.searchParam=data
    },
    setEchartDialog(state,data:boolean){
      state.echartDialog=data
    },
    setSort(state,data){
      state.sortBy=data.sortBy
      state.sortField=data.sortField
    },
    setOutImport(state,data:boolean){
      state.outImport=data
    },
    resetTable(state){
      state.sortField = ''
      state.sortBy = ''
      state.selectRows = []
      state.page = 1
      state.pageSize = 15
    },
    //
    setTreeStyle(state,val){
      state.treeStyle=val
    },
    resetTreeStyle(state){
      state.treeStyle={'treeNum1':false}
    },
    //
    // 失去焦点事件
    setInputBlur(state){
      state.inputBlur=!state.inputBlur
    },
     // 失去焦点事件
    setInputChange(state){
      state.inputChange=!state.inputChange
    },
    // 获取焦点事件
    setInputFocus(state){
      state.inputFocus=!state.inputFocus
    },
    // 当前操作文本框
    setInputName(state,name){
      state.inputName=name
    },
     // 重置查询参数
    resetSearch: (state) => {
      state.searchParam = {}
    },
    setEditData: (state,data) => {
      state.editData =data
    },
    setDialogVisible: (state, boo) => {
      if (boo === false) state.editData = null
      state.dialogVisible = boo
    },
     // 弹窗类型
     setDialogType:(state,val)=>{
      state.dialogType=val
    },
  }
})
export default store
